﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace 学生成绩查询及选课系统.teacher
{
    public partial class studentScore : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
            }
        }
        //static SqlConnection sqlconn;
        //static SqlDataAdapter sdaKc;
        //static DataTable dt = new DataTable();
        //SqlCommandBuilder scb;

        protected void btn_stuno_Click(object sender, EventArgs e)
        {
            if (txt_stuno.Text=="")
            {
                bind();
                return;
            }
            string sql = "select * from grade g where stuno in (select stuno from student where classno in (select classno from teach  where teach.tno='" + Session["user"] + "'))" + " and stuno like '%" +txt_stuno.Text + "%'";
            DataTable dt = DBAccess.GetTable(sql);
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            
        }
        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            
        }
        public void bind()
        {
            string sql = "select stuno ,cno,score,status from grade g where stuno in (select stuno from student where classno in (select classno from teach  where teach.tno='" + Session["user"].ToString() + "'))";
            DataTable dt = DBAccess.GetTable(sql);
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            //scb = new SqlCommandBuilder(sdaKc);
            //for (int i = 0; i < dtKc.Columns.Count; i++)
            //{
            //    dtKc.Rows[e.RowIndex][i] = e.NewValues[i].ToString();
            //}
            //sdaKc.Update(dtKc);
            //GridView1.EditIndex = -1;
            //bind();
        }

        protected void GridView1_RowEditing1(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;//设置要编辑的这行的索引就是当前点前的这行的索引
            bind();
        }

        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            GridView1.EditIndex = -1;
            bind();
        }

        protected void GridView1_RowUpdating1(object sender, GridViewUpdateEventArgs e)
        {
            //int index = e.RowIndex;
            //GridViewRow row = GridView1.Rows[index];
            //String stuno = (GridView1.Rows[e.RowIndex].Cells[2].Controls[0] as TextBox).Text.ToString(); /*获取要更新的数据*/
            //String cno = (GridView1.Rows[e.RowIndex].Cells[2].Controls[0] as TextBox).Text.ToString(); /*获取要更新的数据*/
            //String score = (GridView1.Rows[e.RowIndex].Cells[2].Controls[0] as TextBox).Text.ToString(); /*获取要更新的数据*/
            //String status = (GridView1.Rows[e.RowIndex].Cells[2].Controls[0] as TextBox).Text.ToString(); /*获取要更新的数据*/
            ////string stuno = ((TextBox)row.FindControl("stuno")).Text;
            ////string cno = ((TextBox)row.FindControl("cno")).Text;
            ////string score = ((TextBox)row.FindControl("score")).Text;
            ////string status = ((TextBox)row.FindControl("status")).Text;
            //String sql = "update grade set score='" + score + "',status='" + status + "'" + " where stuno='" + stuno + "' and cno='" + cno + "'";
            //DBAccess.GetState(sql);

            GridView1.EditIndex = -1;
            bind();


        }

        protected void btn_cno_Click(object sender, EventArgs e)
        {
            if (txt_cno.Text == "")
            {
                bind();
                return;
            }

            string sql = "select * from grade g where stuno in (select stuno from student where classno in (select classno from teach  where teach.tno='" + Session["user"] + "'))" + " and cno like '%" + txt_cno.Text + "%'";
            DataTable dt = DBAccess.GetTable(sql);
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            return;
        }
      
    }
}